using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum InputCommandType
{
    Idle,
    MoveForward,
    MoveBack,
}

public struct InputCommand
{
    public InputCommandType commandType;
}

public class PlayerInput : MonoBehaviour
{
    public static PlayerInput Instance { get; private set; } = null;

    public List<InputCommand> commands;

    void Awake()
    {
        Instance = this;
        commands = new List<InputCommand>(32);
    }

    private void OnDestroy()
    {
        Instance = null;
    }

    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        bool move = !Mathf.Approximately(horizontal, 0.0f);
        bool moveLeft = Input.GetKey(KeyCode.LeftArrow);
        bool moveRight = Input.GetKey(KeyCode.RightArrow);

        commands.Clear();
        if (move && (moveLeft || moveRight))
        {
            if(moveLeft)
            {
                commands.Add(new InputCommand
                {
                    commandType = InputCommandType.MoveBack,
                });
            }
            else
            {
                commands.Add(new InputCommand
                {
                    commandType = InputCommandType.MoveForward,
                });
            }
        }
        else
        {
            commands.Add(new InputCommand
            {
                commandType = InputCommandType.Idle,
            });
        }
    }
}
